package com.wsllx.springboot.config;

import com.wsllx.springboot.interfac.AutoConfiguration;
import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

/**
 * 导入配置类
 */
public class ShiGuangImportSelect implements DeferredImportSelector {
	@Override
	public String[] selectImports(AnnotationMetadata importingClassMetadata) {
		//利用SPI技术，将实现了AutoConfiguration文件中获取自动配置类的名字
		ServiceLoader<AutoConfiguration> serviceLoader = ServiceLoader.load(AutoConfiguration.class);
		
		List<String> list = new ArrayList<>();
		for (AutoConfiguration autoConfiguration : serviceLoader) {
			list.add(autoConfiguration.getClass().getName());
		}
		
		return list.toArray(new String[0]);
	}
}
